"""
@name : 06.信号锁
@author : wenyao
@projectname: xsfh
"""
import threading
import time

num = 0
def sum_num(i):
    # lock.acquire()  #加锁
    with lock:
        global num
        time.sleep(0.5)
        num += i
        print(num)
    print("xxxxxxxxxxx")
    # lock.release()  #释放锁

lock = threading.BoundedSemaphore(2)  #定义了两把锁，同时可以有两个线程去执行
lock.release()
for i in range(5):
    t = threading.Thread(target=sum_num,args=(i,))
    t.start()